
package util;

import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;


public class JSFUtil {
    
    
    public static void addMessage(String msg) {
        FacesContext.getCurrentInstance()
                    .addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_INFO,
                msg,null)); 
    }
    
    public static void addMessage(Severity type, String msg) {
        FacesContext.getCurrentInstance()
                    .addMessage(null,
                    new FacesMessage(type,msg,null));
    }
    
    
    
    public static void addMessage(String form,String component,String msg) {
        
        FacesMessage facesMessage = new FacesMessage(msg);
        FacesContext.getCurrentInstance()
                    .addMessage(form+":"+component,facesMessage);
    }
    
   public static EntityManager getEntityManager() {
        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ec = fc.getExternalContext();
        
        HttpServletRequest request = (HttpServletRequest)
                ec.getRequest();
        return (EntityManager) request.getAttribute("entityManager");
  }
   
   public static String getParametro(String nome) {
        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ec = fc.getExternalContext();
        
        HttpServletRequest request = (HttpServletRequest)
                ec.getRequest();
        
        return request.getParameter(nome);
       
   }
   
   
   
   
   
  
   
   
   
    
}
